<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="../master/head.jsp"%>
</head>
<%@ include file="IsStudent.jsp"%>
<body>
<div id="container">
<div id="wrapper">
<div id="sidebar">
<div id="sb_top"><%@ include file="../master/sbTop.jsp"%>
</div>

<div class="sb_content"><!--##########--> <!-- Start Menu --> <%@ include
	file="../master/studentMenu.jsp"%> <!-- Profile -->
<%@ include file="../master/profile.jsp"%> <!-- links -->
<%@ include file="../master/links.jsp"%>
<div class="copyright"><%@ include file="../master/copyright.jsp"%>
</div>

</div>
<!-- /sb_content --></div>
<!-- /sidebar --> <!-- Top -->
<div id="header"><%@ include file="../master/header.jsp"%>
</div>


<!-- Start main content -->
<div id="content">
<div id="intro">
<div class="intro_t">
<h1><span>..</span>Welcome to<span>..</span></h1>
<h2>student project managment system</h2>

</div>
</div>
<!-- /intro --> <%@ page import="java.util.*,java.sql.*"%>
<%
	String un = (String) session.getAttribute("un");
	int id = (Integer) session.getAttribute("id");

	String check[] = new String[3];
	int projId[] = new int[3];

	check = request.getParameterValues("pro");
	for (int i = 0; i < check.length; i++)
	{
		if (check[i] == null)
			projId[i] = 0;
		else
			projId[i] = Integer.parseInt(check[i]);

		out.println("Check  " + i + " | " + projId[i]);
	}

	out.println("<h1>Hi " + un
			+ " <a href='logout.jsp' >LOGOUT</a></h1>");
	String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

	try
	{
		Class.forName(driver);

		Connection connection = DriverManager.getConnection(
				"jdbc:odbc:SPMS", "", "");

		Statement statement = connection.createStatement();
		ResultSet res;
		int result = 0;
		for (int j = 0; j < projId.length; j++)
		{
			if (projId[j] != 0)
			{
				String query = "SELECT * FROM StudentProject WHERE StudentId="
						+ id + "AND ProjectId =" + projId[j];
				res = statement.executeQuery(query);
				if (res.next())
				{
					out.println("You Alredy have this Project");

				} else
				{
					out.println("else" + projId[0]);
					query = "INSERT INTO StudentProject(StudentId,ProjectId) values ( "
							+ id + "," + projId[j] + ")";
					result = statement.executeUpdate(query);

				}

			}
		}
		if (result == 1)
			response.sendRedirect("../Student/myChoice.jsp");
		else
			response.sendRedirect("../Student/index.jsp");
	} catch (ClassNotFoundException cnfe)
	{
		out.println("No such class: " + driver);
	} catch (SQLException se)
	{
		out.println("SQLException: " + se);
	}
%>
</div>
<!-- /content --></div>
<!-- /wrapper -->
<div class="clear">&nbsp;</div>
<!-- Important! Fix the problem of height in Firefox --></div>
<!-- /Container -->


</body>
</html>